package com.youmingxing.adpter.selfInfo;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.youmingxing.R;
import com.youmingxing.bean.selfinfo.Popularity;
import com.youmingxing.utils.ViewHolderUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 我的人气值
 */
public class PopularityAdapter extends BaseAdapter{
    private List<Popularity> mList;
    private TextView popularityValuesTv;
    private TextView popularityTime;
    private TextView popularitymethodTv;
    private View viewLine;
    private Context mContext;

    public PopularityAdapter(Context mContext) {
        this.mContext = mContext;
        mList = new ArrayList<>();
    }

    public void setData(List<Popularity> list) {
        if (list == null)
            return;
        if (mList == null) {
            mList = list;
        } else {
            mList.clear();
            mList.addAll(list);
        }
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        if ((null != mList && mList.size() > 0) && (position >= 0 && position < mList.size())) {
            return mList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView( int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_popularity, null);
        }
        popularityValuesTv = ViewHolderUtils.getViewHolderView(convertView, R.id.popularity_values);
        popularityTime = ViewHolderUtils.getViewHolderView(convertView, R.id.popularity_time);
        popularitymethodTv = ViewHolderUtils.getViewHolderView(convertView, R.id.popularitymethod);
        viewLine = ViewHolderUtils.getViewHolderView(convertView, R.id.view1);
        if (position==0) {
            viewLine.setVisibility(View.GONE);
        } else {
            viewLine.setVisibility(View.VISIBLE);
        }
        popularityValuesTv.setText(mList.get(position).popularityValues);
        popularityTime.setText(mList.get(position).popularityTime);
        popularitymethodTv.setText(mList.get(position).popularitymethod);
        return convertView;
    }
}